home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / GoodBye / JohnKennedy / February96.lha / MASTERCLASS / MASTERMAY.LHA / MasterMay.doc next >
Encoding:
Text File  |  1996-03-01  |  10.6 KB  |  428 lines

  1.  
  2.  
  3. Masterclass
  4.  
  5.  
  6. Using ARexx with other programs can add new features and
  7. automate existing ones. Here's how...
  8.  
  9.  
  10.  
  11. We've already seen that ARexx is a powerful and elegant
  12. programming language in its own right. However, the real
  13. power of ARexx comes when it is combined with other
  14. programs.
  15.  
  16. Remember that the Amiga can multitask many applications at
  17. once with no effort, and so it's possible to run, say a
  18. graphics program, and whilst that is happening start an
  19. ARexx script running. It's also possible to make use of
  20. specific features of the graphics program from the ARexx
  21. script. Here's how.
  22.  
  23. In order for an application program to be used with ARexx,
  24. it must have what is referred to as an "ARexx Port". This
  25. means that when the operating systems sends a command to a
  26. certain location, the application program will recognise it.
  27. It's up the the application to deal with the ARexx command,
  28. and perform an action or return a value to the ARexx script.
  29. For example, an ARexx paint program may accept commands such
  30. as "Plot" or "Circle" and perform a suitable action on the
  31. screen.
  32.  
  33. Here's an example of how you would use ARexx to work with
  34. another program. In this case we'll use AdPro (the Art
  35. Department Professional) as our ARexx compatible application
  36. program.
  37.  
  38. Remember that an ARexx program or script is simply a plain
  39. text file, and so it can be created with any text editor and
  40. saved to disk or to RAM disk. Most programs have there own
  41. little foibles when it comes to dealing with ARexx, and
  42. AdPro is no exception. If you create the script and save it
  43. to the directory ADPROSCRIPTS: with a filename such as
  44. "f8.adpro", when you press the Funtion8 key AdPro will run
  45. the scipt. This is very useful, as it saves you from opening
  46. a Shell window and typing "rx myprogram.rexx" everytime --
  47. although occasionally this is exactly what you want to do,
  48. especially in long batch processing jobs.
  49.  
  50. Here's what a sample ARexx script looks like, line by line.
  51. ARexx works by allowing the host programs to
  52. make new functions available, and so some of the commands
  53. don't look familiar and certainly won't work with other host
  54. programs. This is simply because they are AdPro commands,
  55. not ARexx functions.
  56.  
  57. (Note to art people: please include the lines between
  58. "%" in a different font, and remove the "%"s. I'm trying to
  59. add comments to the listing to explain each line, so please
  60. make it clear the text % between markers like this % is not
  61. part of the listing, but only explanitory text which should
  62. not be typed in.)
  63.  
  64.  
  65.  
  66.  
  67.  
  68. Example Listing
  69.  
  70.  
  71.  
  72. /*
  73.     Example Program using AdPro
  74. */
  75.  
  76.  
  77. % All ARexx programs must start with a comment %
  78.  
  79. ADDRESS "ADPro"
  80.  
  81. % This tells the ARexx system which host program to use.
  82. This is the special Arexx "Port name" you hear about. If you
  83. get it wrong, the script won't work as the AdPro commands
  84. won't be found. You must get the upper and lower case
  85. letters correct too! %
  86.  
  87. OPTIONS RESULTS
  88.  
  89. % this is a special ARexx command to inform the system that
  90. some commands will be returning values to the script for
  91. processing %
  92.  
  93. GETFILE
  94.  
  95. % This is an ADPro command, not an ARexx command. It makes
  96. AdPro put up a file requestor and ask for a file from the
  97. user %
  98.  
  99. filename = ADPRO_RESULT
  100.  
  101. % This is an ARexx command -- the variable called "filename"
  102. is set to the value returned in the special variable called
  103. ADPRO_RESULT. In this case, ADPRO_RESULT will containt the
  104. name of the file the user selected %
  105.  
  106. okay1 "File name is" filename
  107.  
  108. % This is an AdPro command. Rather than use the ARexx SAY to
  109. print test to the Shell, this AdPro command opens a window
  110. on the AdPro screen and displays the text %
  111.  
  112. lformat "universal"
  113.  
  114. % This is an AdPro command, and it sets the loader to be
  115. universal i.e. automatically detect and load the file %
  116.  
  117. load filename
  118.  
  119. % The is an AdPro command, and it loads the file passed to
  120. it -- in this case the name was stored in the ARexx variable
  121. called "filename" %
  122.  
  123. xsize
  124.  
  125. % This is an AdPro command to get the width of the loaded
  126. image file %
  127.  
  128. x=ADPRO_RESULT
  129.  
  130. % This is an ARexx command to assign the width to the
  131. variable called "x" %
  132.  
  133.  
  134. ysize
  135. y=ADPRO_RESULT
  136.  
  137. % As before, although this time the height %
  138.  
  139. okay1 "File is " x "wide and " y "tall."
  140.  
  141. % This AdPro command will print text in a box on the AdPro
  142. screen %
  143.  
  144.  
  145.  
  146.  
  147. -------------------------------------------------
  148.  
  149.  
  150. You can see there is really nothing to it, because AdPro
  151. does all the hard work for us. All we do is automate the
  152. pressing of the buttons by calling the relevant commands
  153. directly. The AdPro documentation includes full details of
  154. all the commands which are available, and many example
  155. script are supplied. Some of the scripts will process all
  156. the frames in an animation, or animate ripple effects.
  157. Anything which AdPro can do can be automated, which is an
  158. excellent way to save time.
  159.  
  160. This is what "Batch processing" is all about. You set up the
  161. computer to repeat a task, and then you go on and do
  162. something else (such as going to bed) whilst it gets on with
  163. it. You are perform tedious operations such as loading in a
  164. thousand images in JPEG format, scaling them and re-saving
  165. them in GIF format. 
  166.  
  167. You can also use batch processing in a creative way: For
  168. example, you might want to make an animation in which the
  169. screen fades out and fades in -- an AdPro script can load
  170. each frame in turn, adust the colours and re-save it. Or you
  171. might want to add ripple effects as though the image was
  172. underwater and rain drops were falling on it. Once again, an
  173. ARexx script can handle all this for you.
  174.  
  175. Sadly AdPro is rather hard to get hold of these days, so
  176. hopefully the next release of Photogenics will feature an
  177. ARexx port.
  178.  
  179. Don't think that graphics programs are the only applications
  180. which benefit from ARexx. Final Writer is an superb Amiga
  181. "Page Processor" program, and the authors were smart enough
  182. to include a full ARexx port. As a result, hundreds of ARexx
  183. macros have been written and many are available for free
  184. from the Aminet (either the CDROMS or the Internet site).
  185. You'll find scripts which will write business letters for
  186. you, draw graphics, wrap text in circles and automatically
  187. create drop shadow effects.
  188.  
  189. Advanced ARexx users can take advantage of the many
  190. libraries and routines available. For example, it's possible
  191. to create a graphical front end with gadgets, windows and
  192. requestors all from an ARexx script. We'll take a look at
  193. these next time.
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205. Box out: Speeding up Arexx programs
  206. -----------------------------------
  207.  
  208.  
  209. ARexx is an interpreted language, which means it is always
  210. going to run rather slowly. One way to speed up ARexx
  211. programs is to compile them, and there are one or two
  212. programs which will do this available. However, it's simpler
  213. to simply stream-line the existing script as much as
  214. Possible: and that is exactly what the program "RexxOpt" I
  215. found on Aminet does. Take a look at the following extracts
  216. from an ARexx script, showing before and after. Although
  217. this is clearly not good programming practice, it is a fair
  218. way to get a little extra speed from programs you have
  219. already written and tested. Make sure you keep a copy of the
  220. original though!
  221.  
  222.  
  223. BEFORE
  224. ------
  225.  
  226. (note: please use a small tight font for the listings, it's
  227. not for typing in rather for demonstrating how the
  228. compression works!)
  229.  
  230.  
  231.  
  232.  
  233.  
  234. /* 
  235.     Search for file names
  236.     ending in #?bak, and then
  237.     delete them if necessary.
  238.          © John Kennedy
  239. */
  240.  
  241. address command /* Use AmigaDOS */
  242.  
  243. /* First, generate list of files & sizes */
  244.  
  245. Say "Making list of all files in current directory...."
  246.  
  247. 'list lformat "%p%n %l" all files > t:templist'
  248.  
  249.  
  250. /* Now, search for those ending in .bak */
  251.  
  252. Say "Adding up file sizes.."
  253.  
  254. infile='infile'
  255. outfile='outfile'
  256.  
  257. total_size=0
  258. number=0
  259.  
  260. call open(outfile,'t:report','w')
  261. call open(infile,"t:templist",'r')
  262.  
  263. do while ~eof(infile)
  264.     data=readln(infile)
  265.     if data~=''  then do
  266.         parse var data namepath " " size
  267.         if size='empty' then size=0
  268.         test=right(namepath,4)
  269.         if (test='.bak') then do
  270.             total_size=total_size+size
  271.             number=number+1
  272.             call writeln(outfile,namepath)
  273.         end
  274.     end
  275. end
  276. call close(infile)
  277. call close(outfile)
  278.  
  279.  
  280.  
  281. AFTER
  282. -----
  283.  
  284. /* Optimized with RexxOpt 1.7 */
  285. address command;Say "Making list of all files in current
  286. directory....";'list lformat "%p%n %l" all files >
  287. t:templist';Say "Adding up file
  288. sizes..";infile='infile';outfile='outfile';total_size=0;numb
  289. er=0;call open(outfile,'t:report','w');call
  290. open(infile,"t:templist",'r');do while
  291. ~eof(infile);data=readln(infile);if data~='' then;do;parse
  292. var data namepath " " size;if size='empty' then
  293. size=0;test=right(namepath,4);if (test='.bak')
  294. then;do;total_size=total_size+size;number=number+1;call
  295. writeln(outfile,namepath);end;end;end;call
  296. close(infile);call close(outfile)
  297.  
  298.  
  299.  
  300. Box out: ARexx compatible programs
  301. -----------------------------------
  302.  
  303.  
  304. Here is a list, by no means comprehensive, of some of the
  305. more popular programs to feature ARexx ports. If an
  306. applicate program has an ARexx Port, you can write an ARexx
  307. script to call various features of the application, or
  308. create macros for use within the program. For example, as
  309. both the V-Lab video digitiser and AdPro image processor
  310. have Arexx ports, you could write a script to grab frames
  311. from video, scale them, re-colour them, and save them to
  312. disk: all automatically.
  313.  
  314.  
  315. Ami-Back
  316.         Disk backup and maintainance suite.
  317.  
  318. AMosaic
  319.         World Wide Web browser.
  320.  
  321. AmiTCP/IP
  322.         TCP/IP networking suite.
  323.  
  324. AMOS Professional
  325.         Programming language.
  326.  
  327. Art Department Professional
  328.         Image processor.
  329.  
  330. Bars & Pipes Professional
  331.         MIDI sequencer and multimedia authoring tool.
  332.  
  333. Blitz Basic II
  334.         Programming language.
  335.  
  336. CanDo
  337.         Programming language and multimedia authoring tool.
  338.  
  339. CygnusEd Professional
  340.         Text editor
  341.  
  342. DeliTracker
  343.         MOD player
  344.  
  345. Directory Opus
  346.         File management.
  347.  
  348. DirWorks
  349.         File management.
  350.  
  351. Distant Suns
  352.         Astronomy program.
  353.  
  354. Final Copy
  355.         Page publisher.
  356.  
  357. GPFax
  358.         Use modem as fax machine.
  359.  
  360. ImageFX
  361.         Image processor.
  362.  
  363. LightWave
  364.         Image renderer.
  365.  
  366. MainActor
  367.         Animation player.
  368.  
  369. Maple
  370.         Mathematics engine.
  371.  
  372. Music-X 2
  373.         MIDI sequencer.
  374.  
  375. NComm
  376.         Terminal emulator.
  377.  
  378. Quarterback
  379.         Disk backup and maintainance suite.
  380.         
  381. Real3D
  382.         Image renderer.
  383.  
  384. SnoopDOS
  385.         System monitor.
  386.  
  387. Spot
  388.         FidoNet mail manager.
  389.  
  390. Termite
  391.         Terminal emulator.
  392.  
  393. Thor
  394.         Mail/news manager.
  395.  
  396. TrapDoor
  397.         FidoNet mailer.
  398.  
  399. TypeSmith
  400.         Font editor.
  401.  
  402. VistaPro
  403.         Landscape generator.
  404.  
  405. V-Lab
  406.         Video digitiser.
  407.  
  408. Xi-Paint
  409.         Paint package.
  410.  
  411.  
  412.  
  413. captions
  414. --------
  415.  
  416.  
  417. may1.iff
  418.  
  419.     FinalWriter is an excellent Page Publishing program, and
  420. it features an ARexx port. This means that it is possible
  421. add your own functions such as the bar chart utility.
  422.  
  423.  
  424. may2.iff
  425.  
  426.     Art Department Professional is (or at least was) the
  427. premier image processing program. It's ARexx facilities made
  428. it the ideal batch processing utility.